﻿var mainToolbar;

// Menu
var mnuSystem,
    mnuManage,
    mnuReport,
    mnuSearch,
    mnuHelp;
    
//Sub menu

// System
var itemLanguage,
    itemSkin,
    itemSystemTime,
    itemLogout;
// Sub item of itemLanguage
var itemEnglish,
    itemVietnamese,
    itemChinese;

// Item of itemSkin    
var itemSkinBlue;

// Manage
var itemAdmin,
    itemIO,
    itemPolygon,
    itemDriverManage;

// Report
var itemAlarmReport,
    itemHistoryReport,
    itemSpeedLineChartReport,
    itemSpeedPieChartReport,
    itemParkingReport,
    itemDistanceReport,
    itemDistanceStaticReport,
    itemPictureReport;
 
// Search   
var itemManual,
    itemGetDirection,
    itemPOI;
    
// Help
var itemGuideDoc,
    itemAbout;
 
 
// Language item
itemEnglish = new Ext.menu.CheckItem({
	text: L10N.menu.system.language.english,
	group: 'langcheckgroup',
	handler: handlerMenu
});

itemChinese = new Ext.menu.CheckItem({
	text: L10N.menu.system.language.chinese,
	group: 'langcheckgroup',
	handler: handlerMenu
});

itemVietnamese = new Ext.menu.CheckItem({
	text: L10N.menu.system.language.vietnamese,
	group: 'langcheckgroup',
	handler: handlerMenu
}); 
 
itemLanguage =  new Ext.menu.Item({
        id: 'itemLanguage',
        text: L10N.menu.system.language.text,
        icon: 'Content/images/comment.png',
        menu: {
            items: [itemEnglish, itemVietnamese, itemChinese]
        }
});   


// Sub item of skin

//var menuskinblue = new Ext.menu.CheckItem({
//    text: _TrackerMain_Skin_Blue,
//    checked: true,
//    group: 'skincheckgroup',
//    handler: handlerMenu
//});

//var menuskinindigo = new Ext.menu.CheckItem({
//    text: _TrackerMain_Skin_Indigo,
//    group: 'skincheckgroup',
//    handler: handlerMenu
//});

//var menuskinblack = new Ext.menu.CheckItem({
//    text: _TrackerMain_Skin_Black,
//    group: 'skincheckgroup',
//    handler: handlerMenu
//});

//var menuskinolive = new Ext.menu.CheckItem({
//    text: _TrackerMain_Skin_Olive,
//    group: 'skincheckgroup',
//    handler: handlerMenu
//});



itemSkin = new Ext.menu.Item({
    id: 'itemSkin',
    text: L10N.menu.system.skin.text,
    icon: 'Content/images/theme.png',
    menu: {
        //items: [menuskinblue, menuskinindigo, menuskinblack, menuskinolive]
    }
});

itemSystemTime = new Ext.menu.Item({
    id: 'itemSystemTime',
    icon: 'Content/images/clock.png',
    text:  L10N.menu.system.systemtime,
    handler: handlerMenu
});

itemLogout = new Ext.menu.Item({
    id: 'itemLogout',
    text: L10N.menu.system.logout,
    icon: 'Content/images/logout16.gif',
    handler: handlerMenu
});

mnuSystem = new Ext.menu.Menu({
    id: 'mnuSystem',    
    icon: 'Content/images/computer.png',
    items: [itemLanguage, itemSkin, itemSystemTime,'-', itemLogout]
});
//-----------------------------------------------------
itemAdmin =  new Ext.menu.Item({
    text: L10N.menu.manage.admin,
    icon: 'Content/images/wrench.png',
    handler: handlerMenu
});

itemIO = new Ext.menu.Item({
    text: L10N.menu.manage.io,
    icon: 'Content/images/tag_edit.gif',
    handler: handlerMenu
	// function() {
//                    if (Ext.getCmp('coustomerconfigwin') == null)
//                        showCustomerConfigWindow()
//                    else
//                        Ext.getCmp('coustomerconfigwin').show();

	
    // }
});
itemPolygon = new Ext.menu.Item( { 
    text: L10N.menu.manage.polygon, 
    icon: 'Content/images/snipshot.png', 
    handler: handlerMenu
	// function(){
        //PolygonGeofenceWindow();
    // }
});
itemDriverManage = new Ext.menu.Item({
    text: L10N.menu.manage.driver,
    icon: 'Content/images/user_gray.png',
    handler: handlerMenu
   // hidden: !showVDR
});

mnuManage = new Ext.menu.Menu({
    items: [ itemAdmin, itemIO, itemPolygon, itemDriverManage]
});
//---------------------------------------------------------
itemAlarmReport =  new Ext.menu.Item({
    text: L10N.menu.report.alarm,
    icon: 'Content/images/alarm.png',
    handler: handlerMenu   
});
itemHistoryReport = new Ext.menu.Item({
	text : L10N.menu.report.history,
	icon : 'Content/images/history.png',
	handler : handlerMenu
});

itemSpeedPieChartReport = new Ext.menu.Item({
	text : L10N.menu.report.speedline,
	icon : 'Content/images/record.png',
	handler : handlerMenu
});
itemSpeedLineChartReport = new Ext.menu.Item({
	text : L10N.menu.report.speedline,
	icon : 'Content/images/speed.gif',
	handler : handlerMenu
});
itemParkingReport = new Ext.menu.Item({
	text : L10N.menu.report.parking,
	icon : 'Content/images/parking.png',
	handler : handlerMenu
});
itemDistanceReport = new Ext.menu.Item({
	text : L10N.menu.report.distance,
	icon : 'Content/images/drive.gif',
	handler : handlerMenu
});
itemDistanceStaticReport = new Ext.menu.Item({
	text : L10N.menu.report.distacestatic,
	icon : 'Content/images/collapse-all.gif',
	handler : handlerMenu
});
itemPictureReport =  new Ext.menu.Item({
	text : L10N.menu.report.picture,
	icon : 'Content/images/photo.png',
	handler : handlerMenu
});


mnuReport = new Ext.menu.Menu({
    items: [
            itemAlarmReport, 
            itemHistoryReport,
            itemSpeedLineChartReport,
            itemSpeedPieChartReport, 
            itemParkingReport, 
            itemDistanceReport, 
			itemDistanceStaticReport, 
            itemPictureReport
    ]
})

//---------------------------------------------------------


itemManual =  new Ext.menu.Item({
	text : L10N.menu.search.manual,
	icon : 'Content/images/searchmap16.gif',
	handler : handlerMenu
});
itemGetDirection =  new Ext.menu.Item({
	text : L10N.menu.search.direction,
	icon : 'Content/images/route16.gif',
	handler : handlerMenu
});
itemPOI =  new Ext.menu.Item({
	text : L10N.menu.search.poi,
	icon : 'Content/images/poi.gif',
	handler : handlerMenu
});

mnuSearch  = new Ext.menu.Menu({
    items: [itemManual, itemGetDirection, itemPOI]
});
//---------------------------------------------------------
itemAbout = new Ext.menu.Item({
	text : L10N.menu.help.about,
	icon : 'Content/images/info.png',
	handler : handlerMenu
});
itemGuideDoc = new Ext.menu.Item({
	text : L10N.menu.help.guide,
	icon : 'Content/images/document.png',
	handler : handlerMenu
});
mnuHelp = new Ext.menu.Menu({
    items: [itemGuideDoc, itemAbout]
});

//---------------------------------------------------------
mainToolbar = new Ext.Toolbar({
    items: [
            {
                text: L10N.menu.system.text,
                menu: mnuSystem,
                icon: 'Content/images/computer.png'
            },
            {
                text: L10N.menu.manage.text,
                menu: mnuManage,
                icon: 'Content/images/control.png'
            },
            {
                text: L10N.menu.report.text,
                menu: mnuReport,
                icon: 'Content/images/report.png'
            },
             {
                text: L10N.menu.search.text,
                menu: mnuSearch,
                icon: 'Content/images/search16.gif'
            }
            ,
             {
                text: L10N.menu.help.text,
                menu: mnuHelp,
                icon: 'Content/images/help.png'
            }
            
            
//            { text: _TrackerMain_Manage, menu: menumanager, icon: 'images/control.png' },
//            { text: _TrackerMain_Reports, menu: menureports, icon: 'images/report.png' },
//            { text: _TrackerMain_MenuSearch, menu: menusearch, icon: 'images/search16.gif' },
//			{ text: _TrackerMain_Help, menu: menusupport, icon: 'images/help.png' },
            
    ]
});

function handlerMenu(item){
    switch(item){
        case itemLogout: {
                 Ext.Ajax.request({
                   url: '/Home/logout',    
                   method: 'POST',                   								 
                   success: function(response, opts){
						window.location.href = '/Home';	
				   }
                });
            }
        break;
        case itemAdmin:{
            admin();
        }
        break;
		case itemIO:{
            showCustomerConfigWindow();
        }
		break;
		case itemPolygon:{
		    polygon();
        }
        break;
        case itemDriverManage: {
            driver(null, null, null);
        }
        break;
    case itemAlarmReport:
        {
            alarmWindow();
        }
        break;
        default:{
            alert(item.title);
        }
    };
}